package com.wc.alorithm_blue_bridge._二分.Q3875;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.*;

/**
 * @Author congege
 * @Description 体育健将
 * https://www.lanqiao.cn/problems/3875/learning/?page=1&first_category_id=1
 * @Date Created in 2023/11/25-15:36
 */
public class Main {
    public static void main(String[] args) {
        Input sc = new Input();
        int n = sc.nextInt();
        int k = sc.nextInt();
        Sport[] sports = new Sport[n];
        for (int i = 0; i < n; i++) {
            Sport sport = new Sport();
            sport.a = sc.nextInt();
            sports[i] = sport;
        }
        for (int i = 0; i < n; i++) {
            sports[i].b = sc.nextInt();
            sports[i].setSum();
        }

        Comparator<Sport> comparator = Comparator.comparingInt(o -> o.sum);

        Arrays.sort(sports, comparator);

        long[] pre = new long[n];
        pre[0] = sports[0].sum;
        for (int i = 1; i < n; i++) {
            pre[i] = pre[i - 1] + sports[i].sum;
        }
        // 剩余的时间
        long re;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            re = k - sports[i].sum;
            // 因为后面都比sports[i].sum大
            if (re <= 0) {
                break;
            }
            int left = 0;
            int right = n - 1;
            int mid;
            while (left <= right) {
                mid = left + (right - left) / 2;
                if (mid < i && pre[mid] >= re) {
                    right = mid - 1;
                } else if (mid >= i && pre[mid] - sports[i].sum >= re) {
                    right = mid - 1;
                } else {
                    left = mid + 1;
                }
            }
            ans = Math.max(ans, left + 1);
        }
        System.out.println(ans);
    }

    static class Input {
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt() {
            try {
                in.nextToken();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return (int) in.nval;
        }
    }

    static class Sport {
        int a;
        int b;
        int sum;

        public void setSum() {
            sum = a + b;
        }
    }
}
